package ac.github.os.internal.core.condition.impl.kether

import ac.github.os.internal.core.condition.Condition
import ac.github.os.internal.core.condition.call
import ac.github.os.internal.core.config.StringConfig
import ac.github.os.internal.core.config.get
import ac.github.os.internal.core.trigger.PlayerTrigger
import ac.github.os.internal.session.Session
import taboolib.common.platform.Awake
import taboolib.common.platform.function.adaptPlayer
import taboolib.common5.Coerce
import taboolib.module.kether.KetherShell

@Awake
class KetherCondition : Condition {

    override fun doScreen(session: Session, config: StringConfig): Boolean {
        val string = config.get<String>("value", single = true) ?: return false
        return session.call<PlayerTrigger> {
            Coerce.toBoolean(KetherShell.eval(string, sender = adaptPlayer(it.player)).get())
        }
    }

    override val namespace: String
        get() = "k"
}